package com.qf.business.coupon.controller;

import com.qf.business.coupon.service.CouponService;
import com.qf.entity.base.R;
import com.qf.entity.po.Coupon;
import com.qf.entity.vo.CartPriceJisuanVo;
import com.qf.entity.vo.CartPriceVo;
import com.qf.entity.vo.CouponGetVo;
import com.qf.entity.vo.CouponUseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    /**
     * 新增优惠券
     * @return
     */
    @PostMapping("/insert")
    public R insert(@RequestBody Coupon coupon){
        System.out.println("接收到新增优惠券的数据：" + coupon);
        couponService.insertCoupon(coupon);
        return R.succ();
    }

    /**
     * 查询优惠券列表
     * @return
     */
    @GetMapping("/list")
    public R list(){
        return R.succ(couponService.list());
    }

    /**
     * 领取优惠券
     * @return
     */
    @PostMapping("/getCoupon")
    public R getCoupon(@RequestBody CouponGetVo couponGetVo){
        System.out.println("领取优惠券:" + couponGetVo);
        couponService.getCoupon(couponGetVo);
        return R.succ();
    }

    /**
     * 查询我的优惠券列表
     * @return
     */
    @PostMapping("/listMyCoupons")
    public R listMyCoupons(@RequestBody CouponUseVo couponUseVo){
        System.out.println("查询当前可用的优惠券:" + couponUseVo);
        return R.succ(couponService.listMyCoupons(couponUseVo));
    }

    /**
     * 使用该优惠券
     * @return
     */
    @PostMapping("/useCoupon")
    public R<CartPriceVo> useCoupon(@RequestBody CartPriceJisuanVo cartPriceJisuanVo){
        System.out.println("使用该优惠券：" + cartPriceJisuanVo);
        return R.succ(couponService.useCoupon(cartPriceJisuanVo));
    }
}
